package com.bestcem.xm.award.controller.param.requestaward;

import com.bestcem.xm.award.constant.Constants;
import com.bestcem.xm.award.enums.DeliverSceneEnum;
import com.bestcem.xm.award.enums.DeliverSourceEnum;
import com.bestcem.xm.award.grpc.service.param.requestaward.DeliverParam;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.util.Optional;

/**
 * 投放信息
 *
 * @author jie.yao <jie.yao@idiaoyan.com>
 * @version v1.0
 * @date 2021/8/19 16:37
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class DeliverQuery {

    /**
     * 投放id
     */
    @JsonProperty("deliver_id")
    private String id;

    /**
     * 投放来源 {@link DeliverSourceEnum}
     */
    @JsonProperty("source")
    private Integer source;

    /**
     * 编号
     */
    @JsonProperty("code")
    private String code;

    /**
     * 组织编号
     */
    @JsonProperty("org_code")
    private String orgCode;

    /**
     * 场景 {@link DeliverSceneEnum}
     */
    @JsonProperty("scenes")
    private Integer scene;

    /**
     * (可选) 奖励id
     */
    @JsonProperty("award_id")
    private String awardId;

    /**
     * (可选) 成员id
     */
    @JsonProperty("member_id")
    private String memberId;

    /**
     * 签名
     */
    @JsonProperty("sig")
    private String sig;

    /**
     * 入参转换为service层所需参数
     *
     * @return DeliverParam
     */
    public DeliverParam getDeliverParam() {
        DeliverParam param = new DeliverParam();
        BeanUtils.copyProperties(this, param);
        return param;
    }

    /**
     * 默认值
     */
    public void defaultValue() {
        this.scene = Optional.ofNullable(this.scene).orElse(0);
        this.source = Optional.ofNullable(this.source).orElse(0);
        this.code = Optional.ofNullable(this.code).orElse(Constants.BLANK);
        this.orgCode = Optional.ofNullable(this.orgCode).orElse(Constants.BLANK);
        this.awardId = Optional.ofNullable(this.awardId).orElse(Constants.BLANK);
        this.memberId = Optional.ofNullable(this.memberId).orElse(Constants.BLANK);
    }
}
